﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using SIPO.Library.DataAccess.Report;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.DataAccess.Transaction;
using SIPO.Web.Support;
using Microsoft.Reporting.WebForms;


namespace SIPO.Web.Reports.Transaction
{
    public partial class rptIncome : BasePage
    {
       
           protected override void OnLoad(EventArgs e)
           {
               recExpenseRepo recExpenseDal = new recExpenseRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
               string parameter = string.Empty;

               if (!IsPostBack)
               {
                                  
                   if (Context.Request.Params["PeriodeAwal"] != null || Context.Request.Params["PeriodeAkhir"] != null || Context.Request.Params["SectorID"] != null)
                   {
                       string path = string.Empty;
                       string dPeriodeAwal = string.Empty;
                       string dPeriodeAkhir = string.Empty;
                       try
                       {
                           DateTime? periodeAwal = Context.Request.Params["PeriodeAwal"] == "" ? (DateTime?)null : Helper.FormatDate(Context.Request.Params["PeriodeAwal"], Helper.Culture.Indonesian);
                           DateTime? periodeAkhir = Context.Request.Params["PeriodeAkhir"] == "" ? (DateTime?)null : Helper.FormatDate(Context.Request.Params["PeriodeAkhir"], Helper.Culture.Indonesian);
                           string sPeriodeAwal = string.Format("{0:yyyyMMdd}", periodeAwal);
                           string sPeriodeAkhir = string.Format("{0:yyyyMMdd}", periodeAkhir);

                            dPeriodeAwal = string.Format("{0:dd MMM yyyy}", periodeAwal);
                            dPeriodeAkhir = string.Format("{0:dd MMM yyyy}", periodeAkhir);
                           if (!sPeriodeAwal.Equals(string.Empty) && !sPeriodeAkhir.Equals(string.Empty))
                           {
                               parameter += " WHERE recExpense.TransDate between '" + sPeriodeAwal + "' and '" + sPeriodeAkhir + "'";
                           }

                           try
                           {
                             


                               
                               List<recExpense> Expense = recExpenseDal.GetListReport(parameter);
                               rsViewer.Reset();
                               path = "~/reportviewer/Transaction/rptExpense.rdlc";
                               rsViewer.LocalReport.ReportPath = Server.MapPath(path);
                               ReportDataSource rds = new ReportDataSource();
                               rds.Name = "DataSet1";
                               rds.Value = Expense;

                               ReportParameter p1 = new ReportParameter("Periode", "Periode " + dPeriodeAwal + " s.d " + dPeriodeAkhir);
                               this.rsViewer.LocalReport.SetParameters(new ReportParameter[] { p1 });

                               string filename = "LaporanPenggunaanDana " + dPeriodeAwal + " sd " + dPeriodeAkhir;

                               rsViewer.LocalReport.DisplayName = filename;

                               rsViewer.LocalReport.DataSources.Clear();
                               rsViewer.LocalReport.DataSources.Add(rds);
                               rsViewer.LocalReport.Refresh();
                           }
                           catch (Exception ex)
                           {
                               Response.Write(ex.Message);
                           }
                       }
                       catch {
                           Response.Write("Periode tidak valid !");
                       }
                       //konversi tanggal
                  

                       //isi parameter
                   
                        

                      
                   }
               }
           }

      
    }
}